/*
 * To change this template, choose Tools | Templates and open the template in the editor.
 */
package video;

/**
 * @author root
 */
/**
 * A JMF example xlet for XleTView. PLease note that due to the nature of JMF support in XleTView,
 * this example will NOT work on a normal MHP implementation without a few changes. This is based on
 * an example xlet posted to the XleTView forums by Martin Sveden. A couple of changes have been
 * made to his original version in order to fix minor bugs, and comments have been added. Thanks to
 * Martin and the rest of the XleTView team for their work in helping newcomers to the MHP community
 * to get started with an easy way of developing xlets. It's appreciated, guys, and not just by the
 * newbies! -- Steve Morris
 */
import java.awt.Color;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import javax.tv.xlet.XletStateChangeException;

import org.havi.ui.HContainer;
import org.havi.ui.HScene;
import org.havi.ui.HSceneFactory;
import org.havi.ui.HScreen;
import org.havi.ui.HStaticText;
import org.havi.ui.event.HRcEvent;

public class jmfVideos extends HContainer implements Xlet, KeyListener {

    private boolean habilitaBotoes = false;

    private HStaticText label;

    private HContainer container;

    private XletContext context;

    private HScene scene;

    Canal01 canal01 = new Canal01();

    public void initXlet(XletContext ctx) throws XletStateChangeException {

        container = this;

        this.context = ctx;
        System.out.println("------------initXlet--------------- ");

        scene = HSceneFactory.getInstance().getFullScreenScene(HScreen.getDefaultHScreen().getDefaultHGraphicsDevice());
        container = this;
        scene = HSceneFactory.getInstance().getDefaultHScene(); // para que obtengamos una instancia HScene con los valores por defecto de la misma

        scene.setLayout(null);
        scene.addKeyListener(this);

        scene.setVisible(true);
        scene.requestFocus();

        scene.add(this);

    }

    public void startXlet() {
        System.out.println("------------startXlet--------------- ");
        //canal01.startVideo();
        scene.setSize(720, 576);

        // Seta as propriedades no label
        this.label = new HStaticText("veideoooooo!!!");
        this.label.setFont(new Font("Verdana", Font.PLAIN, 26));//font Tiresias
        this.label.setBounds(10, 150, 700, 200);
        this.label.setForeground(Color.BLACK);
        this.label.setBackground(new Color(255, 255, 255, 200));

        // Adiciona o Label a Scene
        scene.add(label);
        //canal01.startVideo(scene);

        // Adiciona o Label a Scene
        scene.validate();
        scene.setVisible(true);
        scene.repaint();
        scene.requestFocus();
        repaint();
    }

    public void pauseXlet() {

    }

    public void destroyXlet(boolean unconditional) {

    }

    public void keyTyped(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void keyPressed(KeyEvent e) {
        System.out.println("apertou algum botao");
        if ((e.getKeyChar() == HRcEvent.VK_COLORED_KEY_0) && (this.habilitaBotoes == false)) {
            //System.out.println("botao vermelho foi apertado FF tudo");
            System.out.println(e.getSource());

            System.out.println("------------botao vermelho --------------- ");
            scene.remove(label);
            scene.repaint();
            canal01.setScene(scene, container);
            canal01.startVideo();

            this.habilitaBotoes = true;

        } else if (((e.getKeyCode() == 404) || (e.getKeyCode() == 405) || (e.getKeyCode() == 406))) {
            System.out.println("outros botoes");
        }
        if (this.habilitaBotoes == true) {
            canal01.keyPressed(e);
        }

        /*   else if (e.getKeyChar() == HRcEvent.VK_UP) {
               System.out.println("\npara cima o de dentro !!!!!!!!!!");
               canal01 = null;

           } else if (e.getKeyChar() == HRcEvent.VK_DOWN) {
               System.out.println("para direita DENTRO");

           } else if (e.getKeyChar() == HRcEvent.VK_RIGHT) {
               System.out.println("para direita DENTRO");

           } else if (e.getKeyChar() == HRcEvent.VK_LEFT) {
               System.out.println("para esquerda DENTRO");

           } else if (e.getKeyChar() == HRcEvent.VK_ENTER) {
               System.out.println("enter -- DENTRO");

           } else if (e.getKeyChar() == HRcEvent.VK_COLORED_KEY_0) {
               System.out.println("botao vermelho CR_FT----------");
        //            corrigir(reew, --cont);
           } else if (e.getKeyCode() == 404) {
               System.out.println("DENTRO botao verde!!!!");
           }
        */}

    public void keyReleased(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    /**
     * Handle events from the JMF Player.  
     *
     * In this case we only care about two events and ignore any others.
     */
}
